package org.dromara.xyyw.service.impl;

import org.dromara.common.core.utils.MapstructUtils;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.dromara.xyyw.domain.XyywShoppingCart;
import org.dromara.xyyw.domain.bo.XyywShoppingCartBo;
import org.dromara.xyyw.domain.query.XyywShoppingCartQuery;
import org.dromara.xyyw.domain.vo.XyywShoppingCartVo;
import org.dromara.xyyw.mapper.XyywShoppingCartMapper;
import org.dromara.xyyw.service.IXyywShoppingCartService;

import java.util.Collection;
import java.util.List;

/**
 * 购物车Service业务层处理
 *
 * @author yf
 * @date 2024-05-29
 */
@Service
public class XyywShoppingCartServiceImpl extends ServiceImpl<XyywShoppingCartMapper, XyywShoppingCart> implements IXyywShoppingCartService {

    /**
     * 查询购物车
     *
     * @param shoppingCartId 主键
     * @return XyywShoppingCartVo
     */
    @Override
    public XyywShoppingCartVo queryById(Integer shoppingCartId) {
        return baseMapper.selectVoById(shoppingCartId);
    }

    /**
     * 查询购物车列表
     *
     * @param query 查询对象
     * @return XyywShoppingCartVo
     */
    @Override
    public TableDataInfo<XyywShoppingCartVo> queryPageList(XyywShoppingCartQuery query) {
        return PageQuery.of(() -> baseMapper.queryList(query));
    }

    /**
     * 查询购物车列表
     *
     * @param query 查询对象
     * @return XyywShoppingCartVo
     */
    @Override
    public List<XyywShoppingCartVo> queryList(XyywShoppingCartQuery query) {
        return baseMapper.queryList(query);
    }

    /**
     * 根据新增业务对象插入购物车
     *
     * @param bo 购物车新增业务对象
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean insertByBo(XyywShoppingCartBo bo) {
        XyywShoppingCart add = MapstructUtils.convert(bo, XyywShoppingCart.class);
        return save(add);
    }

    /**
     * 根据编辑业务对象修改购物车
     *
     * @param bo 购物车编辑业务对象
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean updateByBo(XyywShoppingCartBo bo) {
        XyywShoppingCart update = MapstructUtils.convert(bo, XyywShoppingCart.class);
        return updateById(update);
    }

    /**
     * 校验并批量删除购物车信息
     *
     * @param ids 主键集合
     * @return Boolean
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Boolean deleteWithValidByIds(Collection<Integer> ids) {
        return removeByIds(ids);
    }
}
